package com.ruoyi.web.controller.base;

import com.ruoyi.base.domain.BaseNoticeBar;
import com.ruoyi.base.service.IBaseNoticeBarService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 内容轮播Controller
 *
 * @author zzp
 * @date 2022-10-18
 */
@RestController
@RequestMapping("/base/bar")
public class BaseNoticeBarController extends BaseController {
    @Autowired
    private IBaseNoticeBarService baseNoticeBarService;

    /**
     * 查询内容轮播列表
     */
    @PreAuthorize("@ss.hasPermi('base:bar:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseNoticeBar baseNoticeBar) {
        startPage();
        List<BaseNoticeBar> list = baseNoticeBarService.selectBaseNoticeBarList(baseNoticeBar);
        return getDataTable(list);
    }

    /**
     * 导出内容轮播列表
     */
    @PreAuthorize("@ss.hasPermi('base:bar:export')")
    @Log(title = "内容轮播", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseNoticeBar baseNoticeBar) {
        List<BaseNoticeBar> list = baseNoticeBarService.selectBaseNoticeBarList(baseNoticeBar);
        ExcelUtil<BaseNoticeBar> util = new ExcelUtil<BaseNoticeBar>(BaseNoticeBar.class);
        util.exportExcel(response, list, "内容轮播数据");
    }

    /**
     * 获取内容轮播详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:bar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(baseNoticeBarService.selectBaseNoticeBarById(id));
    }

    /**
     * 新增内容轮播
     */
    @PreAuthorize("@ss.hasPermi('base:bar:add')")
    @Log(title = "内容轮播", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseNoticeBar baseNoticeBar) {
        return toAjax(baseNoticeBarService.insertBaseNoticeBar(baseNoticeBar));
    }

    /**
     * 修改内容轮播
     */
    @PreAuthorize("@ss.hasPermi('base:bar:edit')")
    @Log(title = "内容轮播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseNoticeBar baseNoticeBar) {
        return toAjax(baseNoticeBarService.updateBaseNoticeBar(baseNoticeBar));
    }

    /**
     * 删除内容轮播
     */
    @PreAuthorize("@ss.hasPermi('base:bar:remove')")
    @Log(title = "内容轮播", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseNoticeBarService.deleteBaseNoticeBarByIds(ids));
    }
}
